<template>
  <div class="app-container">  
    <el-form :inline="true" :model="listQuery" class="demo-form-inline">
      <!-- <i class="el-icon-search btn-search" @click="handleShowSearch()"></i> -->
      <div class="btn-box"> 
            <el-button type="success" @click="handleAdd()">新增</el-button>
        <el-button type="primary" @click="handleExport()">同步更新</el-button>
        <!-- <el-button
         
        type='primary'
          icon="el-icon-document"
          
        >导出excel</el-button> -->
     
      </div> 
      <!-- <div   v-show="showbtns==true"  class="search-lf">
        
      
      
      <el-form-item>
        <el-?button  type="primary" plain  @click="getList()">查询</el-?button>
       
      </el-form-item>
      </div> -->
    </el-form>
     

    <el-table
       v-loading="listLoading"  border
 height='650px'
      :data="list"
      fit
      @selection-change="handleSelectionChange"
       highlight-current-row
      style="width: 100%"
    >
    
      <el-table-column type="selection" width="55"></el-table-column>
      <el-table-column align="center" width="130px" label="PO单号">
        <template slot-scope="{row}">
          <span>{{ row.po }}</span>
        </template>
      </el-table-column>
      
      <el-table-column sort align="center" width="100px" label="战区">
        <template slot-scope="{row}">
   
          <span >{{ row.regionName }}</span>
        </template>
      </el-table-column>
      <el-table-column sort align="center" label="省份">
        <template slot-scope="{row}">
          
          <span>{{ row.provinceName }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center"  label="课程编导">
        <template slot-scope="{row}">
          <template v-if="row.rowEdit">
            <el-select filterable
              v-model="corsesList.courseChargeName"
              @change="handleCouseChangeName($event)"
              placeholder="请选择"
            >
              <el-option
                v-for="item in courseChargeList"
                :key="item.id"
                :label="item.name"
                :value="item.name"
              ></el-option>
            </el-select>
          </template>
          <span v-else>{{ row.courseChargeName }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="课程ID">
        <template slot-scope="{row}">
          <span>{{ row.courseId }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="学科门类">
        <template slot-scope="{row}">
          <template v-if="row.rowEdit">
            <el-select filterable v-model="corsesList.subjectCategoryName"    @change="handleChangeSubject($event)"  placeholder="请选择">
              <el-option
                v-for="item in subjectTypeList"
                :key="item.id"
                :label="item.name"
                :value="item.name"
              ></el-option>
            </el-select>
          </template>
          <span v-else>{{ row.subjectCategoryName }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="专业分类">
        <template slot-scope="{row}">
          <template v-if="row.rowEdit">
            <el-input v-model="corsesList.majorCategory" placeholder="请输入"></el-input>
          </template>
          <span v-else>{{ row.majorCategory }}</span>
        </template>
      </el-table-column>
      <el-table-column sort align="center" width="180px" label="课程名称">
        <template slot-scope="{row}">
          <span>{{ row.courseName }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" width='150px' label="前期沟通进度">
        <template slot-scope="{row}">
          <template v-if="row.rowEdit">
            <el-select filterable
              v-model="corsesList.earlyExchangeName"
              @change="handleChangePro2($event)"
              placeholder="请选择"
            >
              <el-option
                v-for="item in courseExchange"
                :key="item.id"
                :label="item.name"
                :value="item.name"
              ></el-option>
            </el-select>
          </template>
          <span v-else>{{ row.earlyExchangeName }}</span>
        </template>
      </el-table-column>

      <el-table-column align="center" label=" 讲师姓名">
        <template slot-scope="{row}">
           <template v-if="row.rowEdit">
          <el-input    v-model="corsesList.teacher"/>
          </template>
          <span v-else>{{ row.teacher }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" width="150px" label="联系方式">
        <template slot-scope="{row}">
           <template v-if="row.rowEdit">
          <el-input    v-model="corsesList.phone"/>
          </template>
          
          <span v-else>{{ row.phone }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column align="center"width="200px" label="客户名称">
        <template slot-scope="{row}">
          <span>{{ row.customerName }}</span>
        </template>
      </el-table-column>-->

      <el-table-column align="center" width='120px' label="课程类别">
        <template slot-scope="{row}">
          <template v-if="row.rowEdit">
            <el-select filterable
              v-model="corsesList.courseTypeName"
              @change="handleChangePro5($event)"
              placeholder="请选择"
            >
              <el-option
                v-for="item in courseTypeList"
                :key="item.id"
                :label="item.name"
                :value="item.name"
              ></el-option>
            </el-select>
          </template>
          <span v-else>{{ row.courseTypeName }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center"  label="拍摄形式">
        <template slot-scope="{row}">
          <template v-if="row.rowEdit">
            <el-select filterable
              v-model="corsesList.shootModeName"
              @change="handleChangePro7($event)"
              placeholder="请选择"
            >
              <el-option
                v-for="item in shootModeList"
                :key="item.id"
                :label="item.name"
                :value="item.name"
              ></el-option>
            </el-select>
          </template>
          <span v-else>{{ row.shootModeName }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="预估数量">
        <template slot-scope="{row}">
          <template v-if="row.rowEdit">
            <el-input v-model="corsesList.estimateQuantity"  />
          </template>
          <span v-else>{{ row.estimateQuantity }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" width='138px' label="预估时长（分钟）">
        <template slot-scope="{row}">
          <template v-if="row.rowEdit">
            <el-input type='number'  v-model="corsesList.estimateTimeLength" />
          </template>
          <span v-else>{{ row.estimateTimeLength }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" width="120px" label="样片确认">
        <template slot-scope="{row}">
          <template v-if="row.rowEdit">
            <el-select filterable v-model="corsesList.sampleConfirm" >
              <el-option key="1" label='1' value='是'></el-option>
              <el-option key="0" label='0' value='否'></el-option>
            </el-select>
          </template>
          <span v-else>{{ row.sampleConfirm }}</span>
        </template>

        <!-- <template slot-scope="{row}">
           <span>{{ row.contractDeliveryTime }}</span>
        </template>-->
      </el-table-column>

      <el-table-column align="center" width="120px" label="开始拍摄日期">
        <template slot-scope="{row}">
          <template v-if="row.rowEdit">
            <el-date-picker
              v-model="corsesList.shootStartDate"
              type="date"
              placeholder="选择日期"
              format="yyyy/MM/dd"
              value-format="yyyy/MM/dd"
            ></el-date-picker>
          </template>
          <span v-else>{{ row.shootStartDate }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" width="120px" label="开始制作日期">
        <template slot-scope="{row}">
          <template v-if="row.rowEdit">
            <el-date-picker
              v-model="corsesList.makeStartDate"
              type="date"
              placeholder="选择日期"
              format="yyyy/MM/dd"
              value-format="yyyy/MM/dd"
            ></el-date-picker>
          </template>
          <span v-else>{{ row. makeStartDate }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" width="120px" label="项目交付日期">
        <template slot-scope="{row}">
          <template v-if="row.rowEdit">
            <el-date-picker
              v-model="corsesList.projectDeliveryDate"
              type="date"
              placeholder="选择日期"
              format="yyyy/MM/dd"
              value-format="yyyy/MM/dd"
            ></el-date-picker>
          </template>
          <span v-else>{{ row.projectDeliveryDate }}</span>
        </template>
      </el-table-column>

      <el-table-column align="center" label="拍摄数量">
        <template slot-scope="{row}">
          <template v-if="row.rowEdit">
            <el-input v-model="corsesList.shootQuantity"   />
          </template>
          <span v-else>{{ row.shootQuantity }}</span>
        </template>
      </el-table-column>

      <el-table-column align="center" label="初版数量">
        <template slot-scope="{row}">
          <template v-if="row.rowEdit">
            <el-input v-model="corsesList.firstEditionQuantity"  />
          </template>
          <span v-else>{{ row.firstEditionQuantity }}</span>
        </template>
      </el-table-column>

      <el-table-column align="center" label="终版数量">
        <template slot-scope="{row}">
          <template v-if="row.rowEdit">
            <el-input v-model="corsesList.endEditionQuantity" ></el-input>
          </template>
          <span v-else>{{ row.endEditionQuantity }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" width='160px' label="终版时长">
        <template slot-scope="{row}">
          <template v-if="row.rowEdit">
          
              <el-input
              v-model="corsesList.endEditionTimeLength"
              placeholder="hh:mm:ss格式"
            ></el-input>
          </template>
          <span v-else>{{ row.endEditionTimeLength }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="宣传片">
        <template slot-scope="{row}">
          <template v-if="row.rowEdit">
            <el-input v-model="corsesList.businessSundryFee"></el-input>
          </template>
          <span v-else>{{ row.businessSundryFee }}</span>
        </template>
      </el-table-column>

      <el-table-column align="center" label="完成度">
        <template slot-scope="{row}">
          <template v-if="row.rowEdit">
            <el-input v-model="corsesList.degreeOfCompletion"></el-input>
          </template>
          <span v-else>{{ row.degreeOfCompletion }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" width='120px' label="课程合同金额">
        <template slot-scope="{row}">
          <template v-if="row.rowEdit">
            <el-input type='number' v-model="corsesList.contractAmount"></el-input>
          </template>
          <span v-else>{{ row.contractAmount }}</span>
        </template>
      </el-table-column>

      <el-table-column align="center" width="100px" label="已回款">
        <template slot-scope="{row}">
          <template v-if="row.rowEdit">
            <el-input v-model="corsesList.contractPaymentReceived"></el-input>
          </template>
          <span v-else>{{ row.contractPaymentReceived }}</span>
        </template>
      </el-table-column>
      <el-table-column class-name="status-col" width="120px" label="未回款">
        <template slot-scope="{row}">
          <template v-if="row.rowEdit">
            <el-input v-model="corsesList.contractOutstandingPayment" ></el-input>
          </template>
          <span v-else>{{ row.contractOutstandingPayment }}</span>
        </template>
      </el-table-column>
      <el-table-column class-name="status-col" width="150px" label="预估供应商总金额">
        <template slot-scope="{row}">
          <template v-if="row.rowEdit">
            <el-input v-model="corsesList.estimatedGenerationCost"></el-input>
          </template>
          <span v-else>{{ row.estimatedGenerationCost }}</span>
        </template>
      </el-table-column>
      <el-table-column class-name="status-col" width="120px" label="供应商已结款">
        <template slot-scope="{row}">
          <template v-if="row.rowEdit">
            <el-input v-model="corsesList.supplierPaidAmount"></el-input>
          </template>
          <span v-else>{{ row.supplierPaidAmount }}</span>
        </template>
      </el-table-column>
      <el-table-column class-name="status-col" width="120px" label="供应商未结款">
        <template slot-scope="{row}">
          <span>{{ row.supplierUnpaidAmount }}</span>
        </template>
      </el-table-column>
      <el-table-column class-name="status-col" width="120px" label="上线平台">
        <template slot-scope="{row}">
          <template v-if="row.rowEdit">
            <el-input v-model="corsesList.onlinePlatform"></el-input>
          </template>
          <span v-else>{{ row.onlinePlatform }}</span>
        </template>
      </el-table-column>

      <el-table-column class-name="status-col"   label="上线情况">
        <template slot-scope="{row}">
          <template v-if="row.rowEdit">
            <el-select filterable
              v-model="corsesList.onlineName"
              @change="handleChangePro6($event)"
              placeholder="请选择"
            >
              <el-option
                v-for="item in CourseLineState"
                :key="item.id"
                :label="item.name"
                :value="item.name"
              ></el-option>
            </el-select>
          </template>
          <span v-else>{{ row.onlineName }}</span>
        </template>
      </el-table-column>
      <el-table-column class-name="status-col" width="120px" label="合同交付时间">
        <template slot-scope="{row}">
          <template v-if="row.rowEdit">
            <el-date-picker
              v-model="corsesList.contractDeliveryDate"
              type="date"
              placeholder="选择日期"
              format="yyyy/MM/dd"
              value-format="yyyy/MM/dd"
            ></el-date-picker>
          </template>
          <span v-else>{{ row.contractDeliveryDate }}</span>
        </template>
      </el-table-column>
      <el-table-column class-name="status-col" width="120px" label="课程进度">
        <template slot-scope="{row}">
          <span>{{ row.courseScheduleName }}</span>
        </template>
      </el-table-column>
      <el-table-column class-name="status-col"   label="状态">
        <template slot-scope="{row}">
          <span>{{ row.courseState }}</span>
        </template>
      </el-table-column>
      <el-table-column class-name="status-col" width="120px" label="课程进度备注">
        <template slot-scope="{row}">
          <template v-if="row.rowEdit">
            <el-input v-model="corsesList.courseScheduleName"></el-input>
          </template>
          <span v-else>{{ row.courseScheduleName }}</span>
        </template>
      </el-table-column>
      <el-table-column class-name="status-col" width="120px" label="上传验收单">
        <template slot-scope="{row}">
          <template v-if="row.rowEdit">
            <el-upload
              :data="dataObj"
              :before-upload="beforeUpload"
               :action="UploadUrl()"
               :on-success="handleImageSuccess"
              :on-remove="handleRemove"
              list-type="picture"
            >
              <!-- <el-button size="mini" type="primary">点击上传</el-button> -->
              <i class="el-icon-upload"></i>
            </el-upload>
          </template>
          <span v-else>{{ row.onlinePlatform }}</span>
        </template>
      </el-table-column>
      <el-table-column class-name="status-col" width="200px" label="验收单描述">
        <template slot-scope="{row}">
          <template v-if="row.rowEdit">
            <el-input v-model="corsesList.acceptanceReportDesc"></el-input>
          </template>
          <span v-else>{{ row.acceptanceReportDesc }}</span>
        </template>
      </el-table-column>

      <el-table-column align="center" fixed="right" label="操作" width="150"> 
        <template slot-scope="{row}">
          <el-button
            v-if="row.rowEdit"
            type="success"
            size="mini"
            icon="el-icon-circle-check-outline"
            @click="confirmRole(row)"
          >保存</el-button>
          <el-button
            v-else
            type="primary"
            size="mini"
           :disabled='editDisabled==true'   icon="el-icon-edit"
            @click="handleEdit(row)"
          >编辑</el-button>

          <el-button
            @click="handleDel(row.id)"
            class="mg-l"
            type="danger"
            size="mini"
            icon="el-icon-delete"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-dialog
      @close='handleClose' :visible.sync="dialogVisible"
      width="50%"
      
       :title="dialogType==='edit'?'编辑课程':'添加课程'"
    >
      <el-form label-width="180px" ref="corsesList" :rules='rules' :model="corsesList" label-position="right">
        <div >
          <el-form-item label="PO单号">
            <el-input readonly v-model="corsesList.po" placeholder="请输入" />
          </el-form-item>
          <el-form-item label="课程名称" prop='courseName'>
            <el-input v-model="corsesList.courseName" placeholder="请输入" />
          </el-form-item>
          <el-form-item width="200px" label="客户名称">
            <el-input disabled v-model="corsesList.customerName" placeholder />
          </el-form-item>
         
          <el-form-item label="战区名称">
            <el-input disabled v-model="corsesList.regionName" placeholder />
          
          </el-form-item>
           <el-form-item label="省份名称">
            <el-input disabled v-model="corsesList.provinceName" placeholder />
           
          </el-form-item>
          <el-form-item label="课程编导" prop='courseChargeName'>
            <!-- <el-input v-model="corsesList.productTypeName" placeholder="请选择" /> -->
            <el-select filterable
              v-model="corsesList.courseChargeName"
              @change="handleCouseChangeName($event)"
              placeholder="请选择课程编导"
            >
              <el-option
                v-for="item in courseChargeList"
                :key="item.id"
                :label="item.name"
                :value="item.name"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="分配时间" prop='distributionDate'>
            <el-date-picker
              v-model="corsesList.distributionDate"
              type="date"
              placeholder="选择日期"
              format="yyyy/MM/dd "
              value-format="yyyy/MM/dd"
            ></el-date-picker>
          </el-form-item>
        </div>
       
      </el-form>
      <div style="text-align:center;">
         <el-button type="primary" @click="confirmRole">确定</el-button>
       <el-button type="danger" class="cancel_border" plain  @click="dialogVisible=false">取消</el-button>
        <!-- <el-button type="success" :disabled='isSure' @click="handleExport">导入PO管理</el-button> -->
      </div>
    </el-dialog>

    <pagination
      v-show="total>=20"
      :total="total"
      :page.sync="listQuery.page"
      :limit.sync="listQuery.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import {
  infoPosCourses,
  addCourses,
  updateCourses,
  delCourse,
  contractPO,
  getProvinces,
  poCourses,
  delSupplierFile,
} from "@/api/supplier";

import {
  getProductType,
  getContractType,
  getCourseType,
  getShootMode,
  getCourseCharge,
  getCourseExchange,
  getCourseSchedule,
  getCourseLineState,
  getSubjectCate,
  
} from "@/api/remote-search";
import {baseUrl2} from "@/api/remote-search";
import { regiosList } from "@/api/user";
import Pagination from "@/components/Pagination"; // Secondary package based on el-pagination

export default {
  props: {
    isEdit: {
      type: Boolean,
      default: false,
    },
  },
  name: "corsesList",
  components: { Pagination },
  filters: {
    statusColorFilter(status) {
      const statusMap = {
        1: "success",
        2: "danger",
        3: "warning",
        4: "info",
        5: " ",
      };
      return statusMap[status];
    },
 
    statusFilter(status) {
      const statusMap = {
        1: "进行中",
        2: "已完成",
        3: "已完成",
        0: "新合同",
      };
      return statusMap[status];
    },
  },
  data() {
    return {
      rules: {
          
         
          courseChargeName: [
            {  required: true, message: '请选择课程编导', trigger: 'change' }
          ],
         
          distributionDate: [
           
            { type: 'string', required: true, message: '请选择分配时间', trigger: 'change' }
          ],
       
          courseName: [
            { required: true, message: '请输入课程名称', trigger: 'blur' }
          ],
          
          
        },
     
      showbtns: false,
       list: [], editDisabled:false,
      coursejd:[],//课程进度备注filter
      downloadLoading: false,
      dataObj: { id: "" },
      courseList: [], //课程编导list
      courseChargeList: [], //课程编导
      courseExchange: [], //前期课程进度
      courseTypeList: [], //课程类别
      shootModeList: [], //拍摄形式
      CourseSchedule: [], //课程进度
      CourseLineState: [], //课程上线状态
      subjectTypeList: [], //学科门类
      onlineList: [], //上线情况
      majorList: [], //专业分类
      multipleSelection: "", //多选
      isSure: true,
      rowEdit: false,
      newPoId: "", //新增之后返回的id
      downloadLoading: false,
      productTypeList: [], //课程编导集合
      productLineList: [], //课程ID集合
      contracTypeList: [], //合同类型
      provinceList: [], //战区省份
      allProvinceList:[],//所有省份
      regiosList: [], // 讲师姓名
      corsesList: {
        contractDeliveryDate: "",
        isTrailer: "0",
      },
      total: 0,
      dialogVisibleMenu: false,
      listLoading: true,
      listQuery: {
        access_token: sessionStorage.getItem("token"),
        page: 1,
        pageSize: 20,
      },

      poId: "", //POid
      rolesList: [],

      dialogVisible: false,
      dialogType: "new",
      checkStrictly: false,

      ids: "",
      idsPo: "",
    };
  },
  created() {
    const id = this.$route.query.id;
    const po = this.$route.query.po;
    this.corsesList.poId = id;
    this.corsesList.po = po;
    this.poId = id;
    this.getList(this.poId);
    this.getListes();
  },
  computed: {},

 methods: {
      handleClose(){
      this.editDisabled = false;
    },
    handleShowSearch() {
      this.showbtns = !this.showbtns;
    },
    UploadUrl(){
       return baseUrl2+'/api/file/course_acceptance_report/upload'
    },
    beforeUpload(file) {
      this.dataObj.id = this.poId;
    
    },
    handleImageSuccess(file) {
      if (file.code == "200") {
        this.$message.success(file.message);
      }
    },
    handleRemove() {
      delSupplierFile(this.poId).then((res) => {
        if (res.data.code == "200") {
          this.$message.success(res.data.message);
        } else {
          this.$message.error(res.data.message);
        }
      });
    },
    handleExport() {
      if (this.multipleSelection.length <= 0) {
        this.$message.error("请选择你要更新的数据");
        return false;
      }
      let data = {
        ids: this.idsPo,
      };
      poCourses(data).then((res) => {
        if (res.data.code == "200") {
          this.$message.success(res.data.message + "请到课程进度管理列表查看");
          this.getList(this.poId);
        } else {
          this.$message.error(res.data.message);
        }
      });
    },
    getListes() {
       getProvinces().then((res) => {
        this.allProvinceList = res.data.data;
      });
      getProductType().then((res) => {
        this.productTypeList = res.data.data;
      });
      getCourseCharge().then((res) => {
        this.courseChargeList = res.data.data;
      });
      getContractType().then((res) => {
        this.contracTypeList = res.data.data;
      });
      getProvinces().then((res) => {
        this.provinceList = res.data.data;
      });
      regiosList().then((res) => {
        this.regiosList = res.data.data.rows;
      });
      getCourseExchange().then((res) => {
        this.courseExchange = res.data.data;
      });
      getCourseType().then((res) => {
        this.courseTypeList = res.data.data;
      });
      getShootMode().then((res) => {
        this.shootModeList = res.data.data;
      });
      getCourseSchedule().then((res) => {
        this.CourseSchedule = res.data.data;
      }),
        getCourseLineState().then((res) => {
          this.CourseLineState = res.data.data;
        });
      getSubjectCate().then((res) => {
        this.subjectTypeList = res.data.data;
      });
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
      console.log(this.multipleSelection);
      let res = [];
      if (this.multipleSelection.length > 0) {
        this.multipleSelection.forEach((r) => {
          res.push(r.id);
        });
        this.idsPo = res.join(",");
        console.log(this.idsPo);
      }
    },
    handleChangePro(id) {
      let obj = {};
      obj = this.productTypeList.find((item) => {
        return item.name === id;
      });
      console.log(obj);
      this.corsesList.productTypeId = obj.id;
    },
    handleChangePro2(id) {
     
      let obj = {};
      obj = this.courseExchange.find((item) => {
        return item.name === id;
      });
      this.corsesList.earlyExchangeId = obj.id;
      
      
    },
   
    handleCouseChangeName(id) {
      let obj = {};
      obj = this.courseChargeList.find((item) => {
        return item.name === id;
      });
      this.corsesList.courseChargeId = obj.id;
    },
    handleChangeSubject(id) {
      let obj = {};
      obj = this.subjectTypeList.find((item) => {
        return item.name === id;
      });
      this.corsesList.subjectCategoryId = obj.id;
    },
   
    handleChangePro3(id) {
      let obj = {};
      obj = this.provinceList.find((item) => {
        return item.province === id;
      });
      this.corsesList.provinceId = obj.provinceId;
    },
    handleChangePro4(id) {
      let obj = {};
      obj = this.regiosList.find((item) => {
        return item.region === id;
      });
      this.corsesList.regionId = obj.id;
    },
    handleChangePro5(id) {
      let obj = {};
      obj = this.courseTypeList.find((item) => {
        return item.name === id;
      });
      this.corsesList.courseTypeId = obj.id;
    },
    handleChangePro6(id) {
      let obj = {};
      obj = this.CourseLineState.find((item) => {
        return item.name === id;
      });
      this.corsesList.onlineId = obj.id;
    },
    handleChangePro7(id) {
      let obj = {};
      obj = this.shootModeList.find((item) => {
        return item.name === id;
      });
      this.corsesList.shootModeId = obj.id;
      console.log(this.corsesList);
    },

    handleChangePro8(id) {
      let obj = {};
      obj = this.CourseSchedule.find((item) => {
        console.log(item);
        return item.name === id;
      });
      this.corsesList.courseScheduleId = obj.id;
    },

    getList(id) {
      console.log(this.poId+'ddd')
      this.listLoading = true;
      infoPosCourses(this.poId)
        .then((response) => {
          this.list = response.data.data;
          
          this.listLoading = false;
        })
        .catch(() => {
          this.listLoading = false;
        });
    },
    handleDel(id) {
      this.$confirm("确定删除该数据?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "error",
      })
        .then(() => {
          delCourse(id).then((res) => {
            if (res.data.code == "200") {
              this.$message.success(res.data.message);
              this.getList(this.poId);
            } else {
              this.$message.error(res.data.message);
            }
          });
          // this.$message({
          //   type: 'success',
          //   message: '删除成功!'
          // });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },

    handlenewContract() {
      this.dialogType = "new";
      this.dialogVisible = true;
      // this.corsesList='';
    },
      handleEdit(row) {
       this.editDisabled=true;
      this.dialogType = "edit"
      //this.dialogVisible = true;
      row.rowEdit = !row.rowEdit;
      this.corsesList = row;
      this.corsesList.id = row.id;
    },
    handleAdd() {
    
      this.dialogType = "new";
      this.dialogVisible = true;
      
       this.$nextTick(() => {
        this.$refs['corsesList'].clearValidate()
      })
    },
    confirmRole(id) {
     
      const isEdit = this.dialogType==='edit';
      if (isEdit) {
       
      if(this.corsesList.endEditionTimeLength){
          var regS = new RegExp("\\：","g");
       this.corsesList.endEditionTimeLength=this.corsesList.endEditionTimeLength.replace(regS,":");
         let tempTime=this.corsesList.endEditionTimeLength;
            let temp=tempTime.split(':');
            if(temp[1]>60||temp[2]>60){
              this.$message.error('请输入正确的时间格式，分钟和秒不能大于60');
             
              row.rowEdit = true;
              return false
            }
      }
   
        updateCourses(this.corsesList).then((res) => {
          if (res.data.code == "200") {
            this.$message.success(res.data.message);
            // row.rowEdit = false;
            // this.dialogVisible = false;
            this.getList(this.poId);
             this.editDisabled=false;
          } else {
            this.$message.error(res.data.message);
          }
        });
        return false;
      }
       this.$refs['corsesList'].validate((valid) => {
          if (valid) {
                  addCourses(this.corsesList).then((res) => {
        if ((res.data.code = "200")) {
          this.newPoId = res.data.code;
          this.$message.success(res.data.message);
          this.dialogVisible = false;

          this.infoPosCourses = ""; //清空新增数组
          this.getList(this.poId);
        }
      });
          }
          })

    },

  },
};
</script>

<style scoped>
.edit-input {
  padding-right: 100px;
}
.cancel-btn {
  position: absolute;
  right: 15px;
  top: 10px;
}
</style>
